<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">

            <h:form prependId="false">
                <p:panel toggleable="true" id="allAssigned" header="All cases are assigned!" rendered="#{batchEntityController.selected.unassignedCases==0}">
                   
                </p:panel>
                <p:panel toggleable="true" id="batchCreate" header="Assign locations for batch ##{batchEntityController.selected.id}" rendered="#{batchEntityController.selected.unassignedCases>0}">
                    <h:panelGrid columns="3">

                        <h:outputLabel value="Amount of unassigned #{batchEntityController.selected.product.productName} : #{batchEntityController.selected.unassignedCases} Cases" for="Completed Goods Location Selection" />


                    </h:panelGrid>
                </p:panel>
                <br/>

                <p:dataGrid id="LocationViewDataGridID" var="item" value="#{completedGoodsLocationEntityController.items}" columns="5">  

                    <p:column>  
                        <p:panel header="#{item.areaCode}" style="text-align:center">  


                            <p:poll interval="1" update="pbAjax" widgetVar="poll" />  
                            <h:outputLabel value="Usage: #{item.usageCase}/#{item.capacityCase}"/>
                            <p:progressBar id="pbAjax" widgetVar="pbAjax" ajax="true" value="#{item.showBarCase}"/>

                            <br />

                            <h:outputLabel for="Remaining" value="Remaining: #{item.remainingCase}" /> 


                            <p:spinner rendered="#{batchEntityController.selected.quantity lt item.remainingCase and item.remainingCase>0}" id="minmax" style="width: 40%"
                                       value="#{item.toAddCase}" min="0" max="#{batchEntityController.selected.unassignedCases}">

                            </p:spinner>



                            <p:spinner rendered="#{batchEntityController.selected.quantity ge item.remainingCase and item.remainingCase>0}" id="minmax2" style="width: 40%" 
                                       value="#{item.toAddCase}" min="0" max="#{item.remainingCase}"/>

                            <h:commandButton disabled="#{batchEntityController.selected.unassignedCases==0 or item.remainingCase==0}" value="Assign" action="#{batchEntityController.addLocation}">
                                <f:setPropertyActionListener target="#{batchEntityController.cGLocation}" value="#{item}" />
                            </h:commandButton>
                                <p:commandButton image="ui-icon ui-icon-search" update="cgLocationDetail" oncomplete="cgLocationDialog.show()" title="View Detail">  

                                <f:setPropertyActionListener value="#{item}"   
                                                             target="#{completedGoodsEntityController.viewLocation}" />  
                            </p:commandButton> 


                        </p:panel>  
                    </p:column>  

                </p:dataGrid>  
</h:form>
            
              <p:dialog header="Location Detail" widgetVar="cgLocationDialog" width="400" height="210" modal="true">  
                <p:outputPanel id="cgLocationDetail" style="text-align:center;" layout="block">  

                    <h:panelGrid width="373" border="3" columns="2" cellpadding="5">  
                        <h:outputLabel for="ClassicNutriBarNuts" value="Classic Nutri Bar (Nuts): " />  
                        <h:outputText id="ClassicNutriBarNuts" value="#{completedGoodsEntityController.classicNutriBarNuts}" />  

                        <h:outputLabel for="ClassicNutriBarFruits" value="Classic Nutri Bar (Fruits): " />  
                        <h:outputText id="ClassicNutriBarFruits" value="#{completedGoodsEntityController.classicNutriBarFruits}" />  

                        <h:outputLabel for="PremiumPowerBarNuts" value="Premium Power Bar (Chocolate Nuts): " />  
                        <h:outputText id="PremiumPowerBarNuts" value="#{completedGoodsEntityController.premiumPowerBarNuts}" />  

                        <h:outputLabel for="PremiumPowerBarFruits" value="Premium Power Bar (Redcurrant Fruits): " />  
                        <h:outputText id="PremiumPowerBarFruits" value="#{completedGoodsEntityController.premiumPowerBarFruits}" />  

                    </h:panelGrid>  
                </p:outputPanel>  
            </p:dialog> 




        </ui:define>
    </ui:composition>

</html>
